<template>
    <div id="result">
        <el-backtop></el-backtop>
        <div class="search-info" >
            <yuqingcontent :onetypeinfo="yuqinginfo"></yuqingcontent>
        </div>

        <div class="search-wenda" >
            <yuqingwenda :qusans="yuqingwenda"></yuqingwenda>
        </div>

        <div class="searchjinji" >
            <div class="jinji-search-title">三、禁忌话语</div>
            <jinjicontent :jj="jinji"></jinjicontent>
        </div>

    </div>
</template>

<script>
    import {getsearch} from "../network/search";
    import Yuqingcontent from "./yuqing/yuqingchild/yuqingcontent";
    import Yuqingwenda from "./yuqing/yuqingchild/yuqingwenda";

    import Jinjicontent from "./jinji/jinjichild/jinjicontent";

    export default {
        name: "searchresult",
        components: {Jinjicontent,  Yuqingwenda, Yuqingcontent},
        data(){
            return {
                word:"",
                yuqinginfo:[],
                yuqingwenda:[],
                jinji:[]
            }
        },
		methods: {
			replaceKeyWord(str,content) {
				return content.replace(new RegExp(str,"g"),'<strong>'+str+"</strong>")
				
			},
			aaa() {
				this.word = this.$route.params.keyword
				console.log(this.word);
				getsearch(this.word).then(res => {
					let sdata = res.data;
					console.log(sdata);
					if(sdata.yuqing_info){
						this.yuqinginfo = sdata.yuqing_info
						for(let i=0;i<this.yuqinginfo.length;i++){
							this.yuqinginfo[i]['content'] = this.replaceKeyWord(this.word,this.yuqinginfo[i]['content'])
							// console.log("替换一回yuqinginfo")
							console.log(this.yuqinginfo[i]['content'])
						}
					}
					if(sdata.yuqing_question){
						this.yuqingwenda = sdata.yuqing_question
						for(let i=0;i<this.yuqingwenda.length;i++){
							this.yuqingwenda[i]['answer'] = this.replaceKeyWord(this.word,this.yuqingwenda[i]['answer'])
							// console.log("替换一回yuqingwenda")
						}
					}
				
					if(sdata.jinji){
						this.jinji = sdata.jinji
						for(let i=0;i<this.jinji.length;i++){
							this.jinji[i]['content'] = this.replaceKeyWord(this.word,this.jinji[i]['content'])
							// console.log("替换一回jinji")
						}
					}
				})
			}
		},
        mounted() {
			
        },
        created() {
            this.aaa()
        },
		watch:{
			'$route':'aaa'
		}
    }
</script>

<style scoped>

    .searchjinji{
        margin: 5px;
        padding: 5px;

    }

     .jinji-search-title{
        font-size: 18px;
        font-weight: bold;
        font-family: FangSong;
    }

</style>